# -*- coding: utf-8 -*-

import mod.server.extraServerApi as serverApi

from enchantBase import EnchantBase

comp = serverApi.GetEngineCompFactory()
levelId = serverApi.GetLevelId()


class Nourish(EnchantBase):
    def __init__(self, system, playerId, enchantData, levels):
        EnchantBase.__init__(self, system, playerId, enchantData, levels)
        pass

    def isArmorEnchant(self):
        return False

    def second(self):
        comp_pos = comp.CreatePos(self.playerId)
        comp_dim = comp.CreateDimension(self.playerId)
        comp_block = comp.CreateBlockInfo(serverApi.GetLevelId())
        foot_pos = comp_pos.GetFootPos()
        pos = (int(foot_pos[0]), int(foot_pos[1]), int(foot_pos[2]))
        dim = comp_dim.GetEntityDimensionId()
        if comp_block.GetBlockLightLevel(pos, dim) > 7:
            comp_item = comp.CreateItem(self.playerId)
            max_durability = comp_item.GetItemMaxDurability(2, 0, False)
            durability = comp_item.GetItemDurability(2, 0)
            add_durability = max_durability / 64 <= 0
            if add_durability <= 0:
                add_durability = 1
            comp_item.SetItemDurability(2, 0, durability + add_durability)
        pass

    def repairing(self, args):
        pass
